<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电长推广</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <!-- 引入 ECharts -->
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #app {

            width: 100vw;
            height: 2595px;
            /* font-size: 0.6rem; */
            margin: 0;
            padding: 0;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            /* background-position: 0 0 / cover; */
            overflow-y: auto;
            background-image: url('https://dc.zygyx.com/miniapp/baoming.png');
            /* background-color: #101129; */
        }

        .el-dialog__header {
            padding: 0;
        }

        .title {
            text-align: center;
            font-size: 4vw;
            font-weight: 700;
            /* color: brown; */
            color: transparent;
            background-image: linear-gradient(to bottom, rgb(173, 0, 0), red);
            -webkit-background-clip: text;
            background-clip: text;
            margin-top: 3vw;
        }

        .label {
            /* color: #333; */
            font-size: 4vw;
            font-weight: 700;
            margin: 5vw 0 4vw;
        }

        .baoming {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 5vw;
            font-weight: 700;
            margin: 7vw;
        }

        .baoming span:last-child {
            color: #f50;
        }

        .input_box {
            width: 100%;
            height: 10vw;
            border: 1px solid rgb(255, 102, 25);
            border-radius: 10px;
            padding: 0 20px;
            font-size: 4vw;
            box-sizing: border-box;
        }

        .el-input__inner {
            border: 1px solid rgb(255, 102, 25);
            border-radius: 8px;
        }

        .fuli {
            padding: 16px;
            background: #ffe9e0;
            border-radius: 10px;
            height: 180px;
        }

        p {
            color: #ff1c0e;
            font-family: PingFang SC;
            font-size: 15px;
            font-weight: 500;
            margin-top: 12px;
        }

        .baofu {
            background: #ff5f10;
            font-size: 17px;
            font-weight: 700;
            height: 30px;
            line-height: 28px;
            display: inline-block;
            padding: 0 10px;
            border-radius: 15px;
            color: aliceblue;
            margin-bottom: 15px;
        }

        .submit {
            width: 100%;
            height: 11vw;

            line-height: 11vw;
            text-align: center;
            font-size: 4vw;
            color: #fff;
            background: linear-gradient(90deg, #f50, #ff2424);
            margin: 7vw 0 0;
            border-radius: 10PX;
        }

        .el-dialog__body {

            position: relative;
            padding: 2vw 5vw;
            background-image: linear-gradient(to bottom,
                    red -21%,
                    white 12%);
        }

        .el-dialog {
            border-radius: 16px;
            /* 你可以根据需要调整这个数值 */
        }

        /* 如果你想要更精细的控制，可以单独设置头部和主体的圆角 */
        .el-dialog__header {
            border-top-left-radius: 12px;
            border-top-right-radius: 12px;
        }

        .el-dialog__body {
            border-top-right-radius: 16px;
            border-top-left-radius: 16px;
            border-bottom-left-radius: 16px;
            border-bottom-right-radius: 16px;
        }

        .submittips {
            width: 100%;
            position: fixed;
            /* left: 50%; */
            bottom:0px;
            /* height: 43px; */
            /* transform: translate(-50%, 0); */
            border-radius: 22px;
            background-repeat: no-repeat;
            background-size: 100% 100%;
            /* background-position: 0 0 / cover; */
            overflow-y: auto;
            background-image: url('https://dc.zygyx.com/miniapp/tijiao.png');
        }

        .el-dialog__close {
            display: none;
        }

        /* .submittips:active {
            background-color: #fdc50e;
        } */
        .msel {
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            background-color: transparent;
        }
    </style>
</head>

<body>
    <div id="app" :style="{height:`${windowHeight}px`}">
        <el-dialog :visible.sync="dialogVisible" width="80%" v-loading="loading" show-close="false">
            <div class="msel" :style="{height:`${modelHeight}px`}">
                <span style="position: absolute;right: 19px;top: 0px;font-size: 9vw;color:#ddc4be  "
                    @click="guanbi">x</span>
                <div class="title">报名</div>
                <div class="label">请输入手机号</div>
                <input v-model="call" placeholder="请输入手机号" class="input_box"></input>
                <!-- <div class="baoming">
                    <span>报名费用：</span>
                    <span>￥398</span>
                </div> -->
                <div class="submit" @click="submitApi">
                    确定报名
                </div>
                <!-- <div class="fuli">
                    <div class="baofu">
                        报名福利
                    </div>
                    <p>·赠送价值108的推文助手季卡会员</p>
                    <p>·赠送价值980元的推文出单课程</p>
                    <p>·官方团队终身答疑陪跑</p>
                    <p>.专厘老师一对一服务</p>
    
                </div> -->
            </div>
        </el-dialog>
        <div class="submittips" @click="submittips" :style="{height:`${submitHeight}px`}">
                <!-- 立即报名 -->
        </div>
    </div>


    <script>
        new Vue({
            el: '#app', // 指定Vue实例控制的DOM元素
            data: { // 定义数据对象
                windowWidth: window.innerWidth,
                windowHeight: 0,
                modelHeight: 0,
                submitHeight:0,
                dialogVisible: false,
                call: '',
                loading: false,
                baseUrl: 'https://v2.zygyx.com/renren-api',//基础路径
            },
            mounted() {
                window.addEventListener('resize', this.onResize);
                setTimeout(() => {
                    this.windowWidth = window.innerWidth;
                    this.windowHeight = window.innerWidth * 4336 / 750
                    this.modelHeight = window.innerWidth * 259 / 423
                    this.submitHeight = window.innerWidth * 176 / 750
                }, 200)
            },
            beforeDestroy() {
                window.removeEventListener('resize', this.onResize);
            },
            methods: {
                onResize() {
                    this.windowWidth = window.innerWidth;
                    this.windowHeight = window.innerWidth * 4336 / 750
                    this.modelHeight = window.innerWidth * 259 / 423
                    this.submitHeight = window.innerWidth * 176 / 750
                },
                submittips() {
                    this.dialogVisible = true
                },
                guanbi() {
                    this.dialogVisible = false
                },
                // 请求接口
                submitApi() {
                    if (this.call == '') {
                        return this.$message.error('手机号不能为空');
                    } else {
                        // 正则来规范用户输入的手机号
                        let reg = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
                        if (reg.test(this.call) == false) {
                            return this.$message.error('手机号格式不正确，请重新输入');
                        }
                    }



                    let that = this;
                    that.loading = true;

                    // 使用fetch发送POST请求
                    fetch(`${this.baseUrl}/townerpop/save`, {
                        method: 'POST', // 方法类型
                        headers: {
                            'Content-Type': 'application/json', // 根据实际情况调整Content-Type
                        },
                        body: JSON.stringify({ mobile: that.call }),

                        // 如果有body数据，取消注释下面一行并根据实际情况调整
                        // body: JSON.stringify({ /* 数据对象 */ }), 
                    })
                        .then(response => {
                            that.$message({
                                message: '恭喜你，报名成功',
                                type: 'success'
                            });
                            that.loading = false;
                            that.dialogVisible = false;
                            that.call = '';
                            console.log(response, 'response');
                            // if (!response.ok) {
                            //     throw new Error('网络响应错误');
                            // }
                            return response.json(); // 假设服务端返回的是JSON格式数据
                        })
                        // .then(data => {

                        // })
                        .catch(error => {
                            that.$message.error(error);
                            that.dialogVisible = false;
                            that.loading = false;
                            console.error('Fetch请求失败:', error);
                            // console.log(error, 'eeeeeeeerrrrrrrrrrrrrrrrr');
                        });
                }

            },
        });
    </script>
</body>

</html>